<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>

<style>
<!--
.cpn li {
	padding: 3px 0;
}
.cpn li a {
	font-weight: bold;
}
-->
</style>
<div class="middle padtop10 myclear">
	<div class="page-content">
		
		<!-- bread crumb -->
		<p id="bread-crumb">
			<a href="<?php echo base_url();?>">
				Trang chủ
			</a>
			<a href="<?php echo site_url('bigdata'); ?>">
				Bigdata monitor
			</a>
			Options Priority
		</p>
		<!-- end bread crumb -->
		<h3>
			Options Priority
		</h3>
		<br />
		<table class="tbl-list" cellpadding="0" cellspacing="0" border="0" width="100%">
			<tr>
				<td class="td-label text-center bold" width="30">
					&nbsp;
				</td>
				<td class="td-label text-center bold" width="50">
					ID
				</td>
				<td class="td-label bold" width="200">
					username
				</td>
				<td class="td-label bold" width="200">
					Full name
				</td>
				<td class="td-label bold">
					Priority
				</td>
			</tr>
			<?php
			foreach($lstUser as $user)
			{
			?>
				<tr>
					<td class="text-center" style="padding: 10px;;">
						<img alt="" src="<?php echo STATIC_DOMAIN; ?>images/delete_icon.png" class="cursor-pointer" onclick="bigdata_priority_del('<?php echo site_url('bigdata/optpriorityaction'); ?>', '<?php echo $user['userid']; ?>', '#imgLoadingPopup', '#ajaxLoadingPopupBackground');" />
					</td>
					<td class="text-center" style="padding: 10px;;">
						<?php echo $user['userid']; ?>
					</td>
					<td style="padding: 10px;;" >
						<?php echo $user['username']; ?>
					</td>
					<td style="padding: 10px;;">
						<?php echo $user['contact_name']; ?>
					</td>
					<td style="padding: 10px;" class="sliderburn">
						<div style="background-image: none;" class="slider " rel="<?php echo $user['userid'];?>" id="slider-<?php echo  $user['userid'];?>">
                        	<input class="slider-input" rel="<?php echo  $user['userid'];?>" value="<?php echo $user['priority'];?>" id="slider-input-<?php echo  $user['userid'];?>"/>
                        </div>
                        <div id="h-value<?php echo  $user['userid'];?>">
                        	Priority = <span id="viewValue<?php echo  $user['userid'];?>" style="font-size: 14px;;"><?php echo $user['priority']; ?></span>
                        </div>
					</td>
					
				</tr>
			<?php
			}
			?>
		</table>
		<br />
		<br />
		
		<table class="marbottom10" width="100%" cellpadding="0" cellspacing="0">
			<tr>
				<td class="td-half">
					<table cellpadding="0" cellspacing="0">
						<tr>
							<td class="padright5 ver-middle">
								<span class="ver-middle bold">User ID</span> <input id="iptUsername" class="hlogin-input text-666 ver-middle" type="text"  style="width: 150px;" />
								<p class="padtop5">
									<span class="ver-middle bold">Pirority</span> <input id="priority" class="hlogin-input text-666 ver-middle" type="text"  style="width: 150px;" />
								</p>
							</td>
							
							<td class="padright5 bold ver-middle">
								<input type="button" value="Thêm" onclick="bigdata_priority_add('<?php echo site_url('bigdata/optpriorityaction'); ?>', '#imgLoadingPopup', '#ajaxLoadingPopupBackground')" />
								
							</td>
						</tr>
					</table>
				</td>
				
				<td class="td-half">
					<table class="float-right" cellpadding="0" cellspacing="0">
						<tr>
							<td class="padright5 ver-middle">
								<input id="iptSuserSearch" name="iptSuserSearch" class="hlogin-input text-666" type="text" style="width: 150px;" />
							</td>
							<td class="padright5 ver-middle">
								<select name="slcSby" id="slcSby">
									<option value="1">Theo username</option>
									<option value="2">Theo tên</option>
								</select>
							</td>
							<td class="padright5 bold ver-middle">
								
								<input type="button" value="Search" onclick="search_user_filter('#iptSuserSearch', '#slcSby', '#slcGroup', '#lstUser', '1', '#imgLoadingPopup', '#ajaxLoadingPopupBackground');" />
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		
		<?php
		if(count($lstGroup) > 0)
		{
		?>
			<div class="myclear">
				<table cellpadding="0" cellspacing="0" class="marbottom10 float-right">
					<tr>
						<td class="ver-middle padright5">
							
							<b> Lọc theo nhóm </b>
							
						</td>
						<td class=" ver-middle">
							<select id="slcGroup" name="slcGroup" onchange="search_user_filter('#iptSuserSearch', '#slcSby', '#slcGroup', '#lstUser', '1', '#imgLoadingPopup', '#ajaxLoadingPopupBackground');">
								<option value="-1">All user</option>
								<option value="0">End User</option>
								<?php
								foreach($lstGroup as $group)
								{
								?>
									<option value="<?php echo $group['groupid']; ?>"><?php echo $group['groupname']; ?></option>
								<?php
								}
								?>
							</select>	
						</td>
						
					</tr>
				</table>
			</div>
		<?php 
		}
		?>
		
		<input type="button" value="Show/Hide result" onclick="hide_search();" />
		<div id="lstUser"></div>
		
		<br />
	</div>
</div>
<img alt="" src="<?php echo STATIC_DOMAIN; ?>images/ajax-loader.gif" id="imgLoadingPopup" style="display: none;" />
<div class="ajaxLoadingPopupBackground" id="ajaxLoadingPopupBackground"></div>
<script type="text/javascript">
	function hide_search()
	{
		$('#lstUser').toggle();
	}
	
	function search_select_user(uid)
	{
		$('#iptUsername').val(uid);
	}
	
	function bigdata_priority_add(url, imdLoading, divLoadingBg)
	{
		var uid = parseInt($.trim($('#iptUsername').val()));
		var val = parseFloat($.trim($('#priority').val()));
		
		if(uid == 'NaN' || val == 'NaN' || uid < 0 || val < 0 || val > 4)
		{
			alert('Bạn nhập đúng dữ liệu');
		}
		else 
		{
			var _onOk = function(data)
			{
				disableAjaxLoadingPopup(imdLoading, divLoadingBg);
				if($.trim(data) == 'login')
				{
					window.location.reload(true);
					return;
				}
				else
				{
					if($.trim(data) == 'notright')
					{
						window.location.reload(true);
						return;
					}
					else
					{
						alert('Update Ok.');
						window.location.reload(true);
						return;
					}
				}
			};
			var onError = function()
			{
				disableAjaxLoadingPopup(imdLoading, divLoadingBg);
			};
			var param = 'act=add&uid=' + uid + '&val=' + val;
			loadAjaxLoadingPopup(imdLoading, divLoadingBg);
			getAjax(url, param, '', '', '', false, _onOk, onError);
		}
	}
	
	function bigdata_priority_del(url, uid, imdLoading, divLoadingBg)
	{
		if(confirm('Bạn đã chắc chắn?'))
		{
			var _onOk = function(data)
			{
				disableAjaxLoadingPopup(imdLoading, divLoadingBg);
				if($.trim(data) == 'login')
				{
					window.location.reload(true);
					return;
				}
				else
				{
					if($.trim(data) == 'notright')
					{
						window.location.reload(true);
						return;
					}
					else
					{
						alert('Update Ok.');
						window.location.reload(true);
						return;
					}
				}
			};
			var onError = function()
			{
				disableAjaxLoadingPopup(imdLoading, divLoadingBg);
			};
			var param = 'act=del&uid=' + uid;
			loadAjaxLoadingPopup(imdLoading, divLoadingBg);
			getAjax(url, param, '', '', '', false, _onOk, onError);
		}
	}
	
	function search_user_filter(keyId, stypeEId, groupId, eId, cPage, imdLoading, divLoadingBg)
	{
		var keyword = $.trim($(keyId).val());
		var stype = $.trim($(stypeEId).val());
		
		var onSuccess = function(data)
		{
			disableAjaxLoadingPopup(imdLoading, divLoadingBg);
			if($.trim(data) == 'login')
			{
				window.location.reload(true);
				return;
			}
			else
			{
				if($.trim(data) == 'notright')
				{
					window.location.reload(true);
					return;
				}
				else
				{
					$(eId).html(data);
					return;
				}
			}
		};
		var onError = function()
		{
			disableAjaxLoadingPopup(imdLoading, divLoadingBg);
		};
		loadAjaxLoadingPopup(imdLoading, divLoadingBg);
		var url = '<?php echo site_url('bigdata/search_user');?>';
		var param = 'stype=' + stype + '&g=' + $.trim($(groupId).val()) + '&cpage=' + cPage + '&keyword=' + UrlEncode.encode(keyword);
		getAjax(url, param, '', '', '', false, onSuccess, onError);
	}
	
	
	$(document).ready(function(){
		$('.sliderburn').find('input').each(function(index){
	    	var id=$(this).attr('rel');
	    	
	        var value = parseFloat($.trim($(this).val())) * 10;
	    	var a=new Slider(document.getElementById("slider-"+id),document.getElementById("slider-input-"+id), 'horizontal', function(val)
	    	{
	    		var strURL="<?php echo site_url('bigdata/updateoptpriority?val=');?>"+val+"&uid="+id;
	    		var success = function(data)
	    		{
	    			var obj = jQuery.parseJSON(data);
	    			if(obj.r == '0')
	    			{
	    				window.location = '<?php echo site_url('login')?>';
	    			}
	    			else if(obj.r == '2')
	    			{
	    				alert('Access denied!');
	    				window.location = '<?php echo site_url(); ?>';
	    			}
	    			else if(obj.r == '1')
	    			{
	    				if(obj.mess == 'ok')
	    				{
	    					alert('Update thành công!');
	    				}
	    			}
	    		};
	    		getAjax(strURL,"",'', '', '', false, success);
	    	},value, 451, {
	    		minimum: 0,
	    		maximum: 40,
	    		unitIncrement: 1,
	    		blockIncrement: 11,
	    		extent: 0,
	    		viewValueId : 'viewValue' + id,
	    		viewValueDivide: 10
	    	});
	    });
  });
</script>